package Concurrent.ReflectTest;

import com.sun.org.apache.xpath.internal.SourceTree;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * Created by wangyg 
 * on 2017/6/15 21:10
 */
public class Person {

	public static void main(String[] args)
			throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
		Person p = new Person();
		Field field = p.getClass().getDeclaredField("NAME");
		Field modifiers = field.getClass().getDeclaredField("modifiers");
		modifiers.setAccessible(true);
		System.out.println(field.getModifiers());
		System.out.println(field.getModifiers() - Modifier.FINAL);
		System.out.println(field.getModifiers() & ~Modifier.FINAL);
		System.out.println(Modifier.toString(field.getModifiers()));
//		modifiers.setInt(field, field.getModifiers() & ~Modifier.STATIC);
		modifiers.setInt(field, field.getModifiers() - Modifier.FINAL);
		field.setAccessible(true);
		field.set(p, "Hello");
//		field.set(p,12);
		System.out.println(field.get(p));
		p.printName();
		p.printAge();
//		Person.class.isPrimitive();
//		System.out.println(0x00000040);
	}


	private  final static String NAME = new String("String");
	private static final Integer age=new Integer(128);

	public Person() {

	}

	public void printName() {
		System.out.println(NAME);
	}

	public void printAge(){
		System.out.println(age);
	}
}
